<template>
    <div>
        <!-- seach区域 -->
        <div class="seach">
            <span class="seachStatus">
                {{$t('complaintime')}}
                <el-date-picker :placeholder="$t('plsset')" v-model="creationTime" width="20%" type="daterange" :range-separator="$t('to')" :start-placeholder="$t('startdate')" :end-placeholder="$t('dateclosed')" format="yyyy-MM-dd" value-format="yyyy-MM-dd" size="mini"></el-date-picker>
            </span>
            <span>
                {{$t('sta')}}
                <el-select v-model="comstolenForm.status" :placeholder="$t('plsset')" size="mini">
                    <el-option :label="'-' + $t('plsset') + '-'" :value="null"></el-option>
                    <el-option :label="$t('pending')" value="PENDING"></el-option>
                    <el-option :label="$t('takenover')" value="CONFIRMED"></el-option>
                    <el-option :label="$t('inprogress')" value="PROCESSING"></el-option>
                    <el-option :label="$t('finish')" value="END"></el-option>
                </el-select>
            </span>
            <span class="seachCSC">
                {{$t('complainant')}}
                <el-input v-model.trim="comstolenForm.recordUserName" :placeholder="$t('plsipt')" size="mini"></el-input>
            </span>
            <span class="seachCSC">
                {{$t('cause')}}
                <el-input v-model.trim="comstolenForm.recordReason" :placeholder="$t('plsipt')" size="mini"></el-input>
            </span>
            <div class="NOUS">
                <el-button type="primary" @click="seach" size="mini" v-preventReClick>{{$t('qury')}}</el-button>
            </div>
        </div>
        <!-- 内容区域 -->
        <el-card class="cardBox">
            <el-table border style="width: 100%" :data="accStolenTab">
                <el-table-column type="index" :label="$t('sernum')" width="50">
                </el-table-column>
                <el-table-column prop="recordReason" :label="$t('cause')">
                </el-table-column>
                <el-table-column prop="recordUserName" :label="$t('complainant')">
                </el-table-column>
                <el-table-column prop="recordUserRole" :label="$t('typeofcomplainant')">
                </el-table-column>
                <el-table-column prop="status" :label="$t('sta')">
                </el-table-column>
                <el-table-column prop="gmtCreate" :label="$t('complaintime')">
                </el-table-column>
                <el-table-column :label="$t('opratn')" width="100" fixed="right">
                    <template slot-scope="scope">
                        <el-link type="primary" @click="getDetails(scope.row)">{{$t('see')}}</el-link>
                        <el-badge value="new" class="item" v-if="(scope.row.type === 0 || scope.row.status === $t('pending')) && scope.row.status !== $t('finish')"></el-badge>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="comstolenForm.pageNum"
                :page-sizes="[10, 15, 20, 30]"
                :page-size="comstolenForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
import {
    getuseraccstolenlist
} from '@/libs/reqlist.js'
export default {
    data () {
        return {
            total: 0,
            creationTime: null,
            comstolenForm: {
                recordUserName: '',
                recordReason: '',
                status: '',
                startTime: null,
                endTime: null,
                pageNum: 1,
                pageSize: 10
            },
            accStolenTab: []
        }
    },
    methods: {
        getUseraccList () {
            getuseraccstolenlist(JSON.stringify(this.comstolenForm)).then(res => {
                if (res.status === 200) {
                    this.total = res.data.total - 0
                    for (let i = 0; i <= res.data.list.length - 1; i++) {
                        let item = res.data.list[i]
                        if (item.recordUserRole === 'MER') item.recordUserRole = this.$t('merchant')
                        if (item.recordUserRole === 'PSN') item.recordUserRole = this.$t('personal')
                        if (item.status === 'PENDING') item.status = this.$t('pending')
                        if (item.status === 'END') item.status = this.$t('finish')
                        if (item.status === 'CONFIRMED') item.status = this.$t('takenover')
                        if (item.status === 'PROCESSING') item.status = this.$t('inprogress')
                    }
                    this.accStolenTab = res.data.list
                }
            })
        },
        seach() {
            if (this.creationTime != null) {
                this.comstolenForm.startTime = this.creationTime[0]
                this.comstolenForm.endTime = this.creationTime[1]
            }
            if (!this.creationTime) {
                this.comstolenForm.startTime = null
                this.comstolenForm.endTime = null
            }
            this.comstolenForm.pageNum = 1
            this.getUseraccList()
        },
        handleSizeChange (newSize) {
            this.comstolenForm.pageSize = newSize
            this.getUseraccList()
        },
        // 监听总页数变化
        handleCurrentChange (newNum) {
            this.comstolenForm.pageNum = newNum
            this.getUseraccList()
        },
        getDetails (data) {
            window.sessionStorage.setItem('stolenId', data.id)
            window.sessionStorage.setItem('gmtCreate', data.gmtCreate)
            this.$router.push('/sec/complaintdetails')
        }
    },
    mounted () {
        this.getUseraccList()
    }
}
</script>

<style lang="less" scoped>
@import './comHand.less';
</style>
